Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
How can I display "-" as long as string length in textbox?

I have this list:

let teams = [
  "real madrid",
  "barcelona",
  "milan",
  "inter",
  "juventus",
  "manchester united",
  "manchester city",
  "liverpool",
  "arsenal",
  "chelsea",
  "bayern munich",
];

I wrote code for choose random item from this list but I want display "-" as long as item length.

For example: choose real madrid ... I want this - - - - - - - - - - in the text box.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use String.prototype.replace() with a small RegExp that will match any non-space character \S, and replace it with a hyphen - (PS: g stands for global replace)

const str = "Real Madrid";

const hyphenated = str.replace(/\S/g, "-");
console.log(hyphenated);

Happy hangman-ing!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!